package com.demo.study.utils;

import java.util.Arrays;
import java.util.Random;

/**
 * ArrayUtil
 *
 * @author Baymax
 * @since 2024-08-07
 */
public class ArrayUtil {
    public static int[] intArray() {
        return new int[]{4, 4, 1, 5, 3, 2};
    }

    public static int[] sortedArray() {
        return new int[]{2, 6, 6, 6, 10, 14, 15, 24, 24};
    }

    public static int[] intRandomArray() {
        return intRandomArray(10);
    }

    public static int[] intRandomArray(int length) {
        int[] nums = new int[length];
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int num = random.nextInt(100);
            nums[i] = num;
        }
        return nums;
    }

    public static void printArray(int[] array) {
        System.out.println(Arrays.toString(array));
    }

    /**
     * 数组元素位置交换
     */
    public static void swap(int[] nums, int i, int k) {
        int temp = nums[i];
        nums[i] = nums[k];
        nums[k] = temp;
    }
}
